/*---------------------------------------------------------------------------
    MSN Proxy
    A SOCKS4 Proxy for MSN Messenger allowing you to change your initial status
    on sign-in and to intercept/change/send messages using plugins. 

    Copyright (C) 2001-2004 Dirk Groot aka MrHuge

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    You can contact me on the following email address:
    mrhuge@users.sourceforge.net
---------------------------------------------------------------------------*/
#include "stdafx.h"

#include <stdio.h>
#include "Plugin.h"

/*---------------------------------------------------------------------------
 * Description:
 *   THostInfo structure instance to which host information will be written.
 *---------------------------------------------------------------------------*/
THostInfo *phiHostInfo;

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called right after this DLL is loaded. It enables you
 *   to provide MSN Proxy with plugin info and to store the address of the
 *   'SendMessage' function.
 * Parameters:
 *   ppiInfo : Pointer to a TPluginInfo struct which must be filled with the name
 *             and author of the plugin
 *   phiHost : Pointer to a THostInfo structure containing information about
 *             MSN Proxy's main window and the address of the 'SendMessage' function
 *---------------------------------------------------------------------------*/
extern "C" void __cdecl Load(TPluginInfo *ppiInfo, THostInfo *phiHost)
{
    // Fill TPluginInfo structure
    strcpy(ppiInfo->acName, "EmptyVC.NET");
    strcpy(ppiInfo->acAuthor, "John Doe");

    // Copy THostInfo structure to my local one
    phiHostInfo = new THostInfo;
    phiHostInfo->hMainWindow = phiHost->hMainWindow;
    phiHostInfo->FSendMessage = phiHost->FSendMessage;




}

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called right before this DLL is unloaded. It enables
 *   you to do some de-initialization.
 *---------------------------------------------------------------------------*/
extern "C" void __cdecl Unload(void)
{
    delete phiHostInfo;
}

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called when the user selects 'Configure...' from this
 *   plugin's context menu in the plugin list. It enables you to display a
 *   configuration window. An empty setup form is included in this project.
 * Parameters:
 *   hParent : Window handle of the window which should be your setup form's owner
 *---------------------------------------------------------------------------*/
extern "C" void __cdecl Setup(HWND hParent)
{
	MessageBox(hParent, "Configuration box goes here...", "MSNProxy", MB_OK | MB_ICONINFORMATION);
}

/*---------------------------------------------------------------------------
 * Description:
 *   Same as the Setup function, but this one is to display an about box about
 *   your plugin.
 * Parameters:
 *   hParent : Window handle of the window which should be your about box's owner
 *---------------------------------------------------------------------------*/
extern "C" void __cdecl About(HWND hParent)
{
	MessageBox(hParent, "About box goes here...", "MSNProxy", MB_OK | MB_ICONINFORMATION);
}

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called when a conversation session is started either
 *   because a remote user started a conversation or because you started a
 *   conversation yourself. MSN Messenger won't display a conversation window
 *   until the remote user has actually sent you a message, so this enables you
 *   to send the remote user a message before he has sent one to you. From here
 *   you can call the phiHostInfo->FSendMessage function (see MessageReceived
 *   for an example).
 * Parameters:
 *   psiSession : Pointer to a TSessionInfo structure containing information
 *                about the new session.
 *---------------------------------------------------------------------------*/
extern "C" void __cdecl StartSession(TSessionInfo *psiSession)
{
}

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called when a session has completely ended, that is
 *   when the connection with the switchboard server is terminated. This enables
 *   you to do some de-initialization. From here you can't call the
 *   phiHostInfo->FSendMessage function.
 * Parameters:
 *   psiSession : Pointer to a TSessionInfo structure containing information
 *                about the ended session.
 *---------------------------------------------------------------------------*/
extern "C" void __cdecl EndSession(TSessionInfo *psiSession)
{
}

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called when a message is received from a remote user.
 *   From here you can call the phiHostInfo->FSendMessage function.
 * Parameters:
 *   pcSessionID     : See the acSessionID member of TSessionInfo
 *   pcSingInName    : SignIn name of the remote user (ie user@hotmail.com)
 *   pcFriendlyName  : Friendly name of the remote user
 *   pcMessage       : Message which has been received
 * Return value:
 *   true            : The incoming message will be passed to MSN Messenger
 *   false           : The incoming message will NOT be passed to MSN Messenger
 *---------------------------------------------------------------------------*/
extern "C" bool __cdecl MessageReceived(char *pcSessionID, char *pcSignInName, char *pcFriendlyName, char *pcMessage)
{
    char acTriggerString[100],
         acResponse[255];

    // Do some parsing
    strcpy(acTriggerString, "!helloplugin");
    if (!strnicmp(pcMessage, acTriggerString, strlen(acTriggerString)))
    {
        // If the message begins with !helloplugin, then send a message
        //   containing 'Hello [Friendly name]!' in MS Sans Serif, 10pt, bold, green.
        sprintf(acResponse, "Hello %s!", pcFriendlyName);
        phiHostInfo->FSendMessage(pcSessionID, false, "FN=Microsoft%20Sans%20Serif; EF=B; CO=008000; CS=0; PF=00;", acResponse);

        // Don't pass the incoming message to MSN Messenger
        return false;
    }

    // If something else has been received, the message can be passed to
    //   MSN Messenger
    return true;
}

/*---------------------------------------------------------------------------
 * Description:
 *   This function will be called when a message is about to be sent to a remote
 *   user. From here you can call the phiHostInfo->FSendMessage function.
 * Parameters:
 *   pcSessionID     : See the acSessionID member of TSessionInfo
 *   pcParticipants  : SignIn names/Friendly names of the participants in this
 *                     conversation. It's formatted as follows:
 *                     "[signin]|[friendly]\r\n[signing]|[friendly]\r\n...."
 *                     Example: "user1@hotmail.com|User%20one\r\nuser2@hotmail.com|User%20two\r\n"
 *   pcMessage       : Message which is about to be sent
 * Return value:
 *   true            : The message will be sent to the remote user
 *   false           : The message will NOT be sent to the remote user
 *---------------------------------------------------------------------------*/
extern "C" bool __cdecl MessageSent(char *pcSessionID, char *pcParticipants, char *pcMessage)
{
    return true;
}

/*---------------------------------------------------------------------------
 * Description:
 *   DLL entry point.
 *---------------------------------------------------------------------------*/
BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
    return TRUE;
}